home *** CD-ROM | disk | FTP | other *** search
/ Enter 2003: The Beautiful Scenery / enter-parhaat-2003.iso / files / frendz.exe / frendz.dcr / Scripts_57_Main Script.ls < prev    next >
Encoding:
Text File  |  2002-12-31  |  10.8 KB  |  455 lines

  1. global gPlay, gPause, gURLScore, gURLEmail, gURLPing, gSoundOn, GAME_ID, CLIENT_ID, ground, key1, gCheater, isMac, isShockwave, gCookiePath, gGameCookieExists, gCheckLegalCookie, gKewlboxFolder, gStartFrame, gOnline, gMessageBox, gMacSound, gStopURL, gDelayButton, VERSION_NUM, gClientURLs, gBannerList, gNewBanner, gScreenLarge, gDrawStage, gRectStage, gChartLoc, gChart, gGoodNetBanner, gGameStarted, gGameTimerObj, gGameSeconds, gClickOnOnce, gNetID, gCheckPing, gEmailNames, gErrorChar, gDecoyScore, gEncryptScore, NUM_ENCRYPT, ENCRYPT_DENOM, ENCRYPT_PATTERN, gDecoyLives, gEncryptLives, gpTicks
  2.  
  3. on stopMovie
  4.   if gMacSound <> VOID then
  5.     set the soundLevel to gMacSound
  6.   end if
  7. end
  8.  
  9. on startMovie
  10.   clearGlobals()
  11. end
  12.  
  13. on startMoviePastLoader
  14.   initScore()
  15.   initGlobals()
  16.   goInitFrameOne()
  17.   resetEverything()
  18.   initStreaming()
  19.   gMessageBox = new(script("p_MessageBox"), 80, 81, 82)
  20.   sound(8).volume = 255
  21.   member("t_Score1").text = "0"
  22.   member("t_Score2").text = "0"
  23.   gStopURL = 0
  24. end
  25.  
  26. on initGlobals
  27.   GAME_ID = 66
  28.   CLIENT_ID = 14
  29.   MAJOR_REV = 1
  30.   MINOR_REV = 0
  31.   VERSION_NUM = 1
  32.   gDelayButton = -1
  33.   case VERSION_NUM of
  34.     1:
  35.       versionLetter = "a"
  36.     2:
  37.       versionLetter = "b"
  38.     3:
  39.       versionLetter = "c"
  40.     4:
  41.       versionLetter = "d"
  42.     5:
  43.       versionLetter = "e"
  44.     6:
  45.       versionLetter = "f"
  46.     7:
  47.       versionLetter = "g"
  48.     otherwise:
  49.       versionLetter = EMPTY
  50.   end case
  51.   theStr = "v" & MAJOR_REV & "." & MINOR_REV & versionLetter
  52.   member("t_VersionNumber").text = theStr
  53.   if VERSION_NUM > 7 then
  54.     alert("Do not have a URL for this version" && theStr)
  55.   end if
  56.   gClientURLs = ["http://www.att.com/tracking/game1", "http://www.att.com/tracking/game2", "http://www.att.com/tracking/game3", "http://www.att.com/tracking/game4", "http://www.att.com/tracking/game5", "http://www.att.com/tracking/game6", "http://www.att.com/tracking/game7"]
  57.   gURLScore = "http://www.kewlbox.com/scores/direct.cfm?"
  58.   gURLEmail = "http://www.kewlbox.com/email/direct.cfm?"
  59.   gURLPing = "http://www.kewlbox.com/ping/ping.cfm?"
  60.   setConditionalMode()
  61.   gPlay = 0
  62.   gPause = 0
  63.   gGameStarted = 0
  64.   gGameSeconds = 0
  65.   gSoundOn = 0
  66.   ground = 1
  67. end
  68.  
  69. on setConditionalMode
  70.   if the runMode contains "Plugin" then
  71.     isShockwave = 1
  72.   else
  73.     isShockwave = 0
  74.   end if
  75.   if (the environment).platform contains "Macintosh,PowerPC" then
  76.     isMac = 1
  77.     gMacSound = the soundLevel
  78.   else
  79.     isMac = 0
  80.     gMacSound = 7
  81.   end if
  82.   if (the environment).internetConnected = #online then
  83.     gOnline = 1
  84.   else
  85.     gOnline = 0
  86.   end if
  87.   gStartFrame = "Main"
  88. end
  89.  
  90. on doShockwaveLoadGraphic
  91.   return isShockwave
  92. end
  93.  
  94. on getDateIndex
  95.   theMonth = (the systemDate).month
  96.   theDay = (the systemDate).day
  97.   theYear = (the systemDate).year
  98.   dateIndex = (theYear * 10000) + (theMonth * 100) + theDay
  99.   return dateIndex
  100. end
  101.  
  102. on checkDate
  103.   dateIndex = getDateIndex()
  104.   expIndex = 20020607
  105.   expDate = "6/07/2002"
  106.   if dateIndex >= expIndex then
  107.     alert("This game has expired.")
  108.     quit()
  109.   else
  110.     alert("This game expires on" && expDate)
  111.   end if
  112. end
  113.  
  114. on getYear
  115.   tempStr = the date
  116.   n = length(tempStr)
  117.   theYear = -1
  118.   firstPos = -1
  119.   lastPos = -1
  120.   repeat with i = 1 to n
  121.     c = chars(tempStr, i, i)
  122.     if (c < "0") or (c > "9") then
  123.       lastPos = i
  124.       if firstPos = -1 then
  125.         firstPos = i
  126.       end if
  127.     end if
  128.   end repeat
  129.   if lastPos >= 0 then
  130.     try1 = value(chars(tempStr, lastPos + 1, n))
  131.     if (try1 >= 1980) and (try1 < 2200) then
  132.       theYear = try1
  133.     end if
  134.   end if
  135.   if (theYear < 0) and (firstPos > 0) then
  136.     try1 = value(chars(tempStr, 1, firstPos - 1))
  137.     if (try1 >= 1980) and (try1 < 2200) then
  138.       theYear = try1
  139.     end if
  140.   end if
  141.   if theYear < 0 then
  142.     theYear = value(chars(tempStr, n - 1, n))
  143.   end if
  144.   if theYear < 80 then
  145.     theYear = theYear + 2000
  146.   else
  147.     if theYear < 100 then
  148.       theYear = theYear + 1900
  149.     end if
  150.   end if
  151.   return theYear
  152. end
  153.  
  154. on resetEverything
  155.   member("t_Level").text = "1"
  156.   member("t_Rows").text = "0"
  157.   member("f_reciveText").text = EMPTY
  158.   gBannerList = [:]
  159.   gScreenLarge = 0
  160.   gDrawStage = (the stage).drawRect
  161.   gRectStage = (the stage).rect
  162.   gNewBanner = 0
  163.   gGoodNetBanner = 0
  164.   gChart = "on"
  165.   gChartLoc = [:]
  166.   l = the number of lines in the text of member "f_ChartLoc"
  167.   repeat with i = 1 to l
  168.     addProp(gChartLoc, i, member("f_ChartLoc").line[i])
  169.   end repeat
  170. end
  171.  
  172. on checkGameTime
  173.   if gGameStarted = 0 then
  174.     gGameStarted = 1
  175.     gGameTimerObj = new(script("p_timer"))
  176.     resetTimer(gGameTimerObj)
  177.     runTimer(gGameTimerObj)
  178.   end if
  179.   gGameSeconds = float(reportTimer(gGameTimerObj))
  180. end
  181.  
  182. on ping
  183.   gNetID = bdGetNetText(gURLPing & GAME_ID & "&clientId=" & CLIENT_ID)
  184.   gCheckPing = 1
  185. end
  186.  
  187. on ping2
  188.   gNetID = bdGetNetText(gURLPing & GAME_ID & "&clientId=" & CLIENT_ID & "&time=" & integer(gGameSeconds))
  189. end
  190.  
  191. on submitEmail
  192.   gEmailNames = EMPTY
  193.   gErrorChar = [1: "\", 2: "\", 3: "#", 4: "?", 5: "%", 6: "\\", 7: "/"]
  194.   repeat with i = 1 to 5
  195.     box = "f_EmailBox" & i
  196.     if member(box).text = EMPTY then
  197.       next repeat
  198.       next repeat
  199.     end if
  200.     put "&" & "email" & i & "=" & member(box).text after gEmailNames
  201.   end repeat
  202.   repeat with y = 1 to 2
  203.     z = getProp(gErrorChar, y)
  204.     repeat with x = 1 to 200
  205.       if gEmailNames.char[x] = "$" then
  206.         delete gEmailNames.char[x]
  207.       end if
  208.     end repeat
  209.   end repeat
  210.   put gURLEmail & "&gameId=" & GAME_ID & "&clientId=" & CLIENT_ID & gEmailNames
  211.   bdWebCommunicate(gURLEmail & "&gameId=" & GAME_ID & "&clientId=" & CLIENT_ID & gEmailNames, 1)
  212. end
  213.  
  214. on setScoreParams
  215.   tempScore = getScore()
  216.   ScoreMod = (tempScore + (3 * GAME_ID)) mod 13579
  217.   key2 = (4 * (ScoreMod * ScoreMod)) + (23 * ScoreMod) + (key1 * 54)
  218.   key2 = key2 mod 1000000
  219.   t = "&score=" & tempScore
  220.   t = t & "&key1=" & key1
  221.   t = t & "&key2=" & key2
  222.   return t
  223. end
  224.  
  225. on postScore
  226.   if gCheater = 0 then
  227.     temp = gURLScore & "gameID=" & GAME_ID & "&clientID=" & CLIENT_ID & setScoreParams()
  228.     bdWebCommunicate(temp, 1)
  229.   end if
  230. end
  231.  
  232. on initScore
  233.   gEncryptScore = []
  234.   gCheater = 0
  235.   NUM_ENCRYPT = 6
  236.   ENCRYPT_DENOM = 117
  237.   ENCRYPT_PATTERN = 214
  238.   setScore(0)
  239. end
  240.  
  241. on rotateByteRight x, n
  242.   n = n mod 8
  243.   x2 = x
  244.   x3 = x
  245.   if n > 0 then
  246.     repeat with i = 1 to n
  247.       x2 = integer(x2 / 2)
  248.       x3 = x3 * 2
  249.     end repeat
  250.     n = 8 - n
  251.     repeat with i = 1 to n
  252.       x3 = x3 * 2 mod 256
  253.     end repeat
  254.     x = x2 + x3
  255.   end if
  256.   return x
  257. end
  258.  
  259. on exclusiveOr x1, x2
  260.   sum = 0
  261.   p2 = 1
  262.   repeat with i = 1 to 8
  263.     m1 = x1 mod 2
  264.     m2 = x2 mod 2
  265.     if (m1 + m2) = 1 then
  266.       sum = sum + p2
  267.     end if
  268.     x1 = integer(x1 / 2)
  269.     x2 = integer(x2 / 2)
  270.     p2 = 2 * p2
  271.   end repeat
  272.   return sum
  273. end
  274.  
  275. on setScore n
  276.   gDecoyScore = n
  277.   last = 0
  278.   repeat with i = 1 to NUM_ENCRYPT
  279.     gEncryptScore[i] = exclusiveOr(n mod ENCRYPT_DENOM, rotateByteRight(ENCRYPT_PATTERN, i - 1))
  280.     last = last + rotateByteRight(gEncryptScore[i], i - 1)
  281.     n = integer(n / ENCRYPT_DENOM)
  282.   end repeat
  283.   gEncryptScore[NUM_ENCRYPT + 1] = last
  284.   put gDecoyScore into member "t_TotalScore"
  285. end
  286.  
  287. on setLives n
  288.   gDecoyLives = n
  289.   last = 0
  290.   repeat with i = 1 to NUM_ENCRYPT
  291.     gEncryptLives[i] = exclusiveOr(n mod ENCRYPT_DENOM, rotateByteRight(ENCRYPT_PATTERN, i - 1))
  292.     last = last + rotateByteRight(gEncryptLives[i], i - 1)
  293.     n = integer(n / ENCRYPT_DENOM)
  294.   end repeat
  295.   gEncryptLives[NUM_ENCRYPT + 1] = last
  296.   put gDecoyLives into member "t_Lives"
  297. end
  298.  
  299. on getScore
  300.   realScore = 0
  301.   last = 0
  302.   repeat with i = NUM_ENCRYPT down to 1
  303.     realScore = (realScore * ENCRYPT_DENOM) + exclusiveOr(gEncryptScore[i], rotateByteRight(ENCRYPT_PATTERN, i - 1))
  304.     last = last + rotateByteRight(gEncryptScore[i], i - 1)
  305.   end repeat
  306.   if last <> gEncryptScore[NUM_ENCRYPT + 1] then
  307.     realScore = 0
  308.     gCheater = 1
  309.   end if
  310.   return realScore
  311. end
  312.  
  313. on getLives
  314.   realLives = 0
  315.   last = 0
  316.   repeat with i = NUM_ENCRYPT down to 1
  317.     realLives = (realLives * ENCRYPT_DENOM) + exclusiveOr(gEncryptLives[i], rotateByteRight(ENCRYPT_PATTERN, i - 1))
  318.     last = last + rotateByteRight(gEncryptLives[i], i - 1)
  319.   end repeat
  320.   if last <> gEncryptLives[NUM_ENCRYPT + 1] then
  321.     realLives = 0
  322.     gCheater = 1
  323.   end if
  324.   return realLives
  325. end
  326.  
  327. on findSoundChannel
  328.   repeat with i = 1 to 5
  329.     if not soundBusy(i) then
  330.       whichChannel = i
  331.       exit repeat
  332.     end if
  333.   end repeat
  334.   if not voidp(whichChannel) then
  335.     return whichChannel
  336.   else
  337.     return 1
  338.   end if
  339. end
  340.  
  341. on saveText text, fileName, dialogBox, appendFile
  342.   fileObj = new(xtra("FileIO"))
  343.   if dialogBox = 1 then
  344.     if the platform contains "Mac" then
  345.       setFilterMask(fileObj, "TEXT")
  346.     else
  347.       setFilterMask(fileObj, "Text Files,*.txt, AllFiles,*.*")
  348.     end if
  349.     fileName = displaySave(fileObj, EMPTY, EMPTY)
  350.     if fileName = EMPTY then
  351.       return 0
  352.     end if
  353.   end if
  354.   if appendFile = 0 then
  355.     openFile(fileObj, fileName, 2)
  356.     delete(fileObj)
  357.   end if
  358.   createFile(fileObj, fileName)
  359.   openFile(fileObj, fileName, 0)
  360.   if status(fileObj) <> 0 then
  361.     err = error(fileObj, status(fileObj))
  362.     alert("Error: " && err)
  363.     return 0
  364.   end if
  365.   setPosition(fileObj, getLength(fileObj))
  366.   writeString(fileObj, text)
  367.   if the platform contains "Mac" then
  368.     setFinderInfo(fileObj, "TEXT ttxt")
  369.   end if
  370.   closeFile(fileObj)
  371.   return 1
  372. end
  373.  
  374. on openAndReadText fileName, dialogBox
  375.   fileObj = new(xtra("FileIO"))
  376.   if dialogBox = 1 then
  377.     if the platform contains "Mac" then
  378.       setFilterMask(fileObj, "TEXT")
  379.     else
  380.       setFilterMask(fileObj, "Text Files,*.txt,All Files,*.*")
  381.     end if
  382.     fileName = displayOpen(fileObj)
  383.     if fileName = EMPTY then
  384.       return EMPTY
  385.     end if
  386.   end if
  387.   openFile(fileObj, fileName, 1)
  388.   if status(fileObj) <> 0 then
  389.     err = error(fileObj, status(fileObj))
  390.     alert("Error:" && err)
  391.     return EMPTY
  392.   end if
  393.   text = readFile(fileObj)
  394.   closeFile(fileObj)
  395.   return text
  396. end
  397.  
  398. on checkPingResult
  399.   if gCheckPing = 1 then
  400.     doExit = 0
  401.     if gpTicks <= 400 then
  402.       if netError(gNetID) = "OK" then
  403.         put netError(gNetID) & "Yes"
  404.         put netTextresult()
  405.         gCheckPing = 0
  406.         if gNewBanner = 0 then
  407.           getNewBanner()
  408.           gNewBanner = 1
  409.         end if
  410.         doExit = 1
  411.       else
  412.         if netError(gNetID) = 4146 then
  413.           gNewBanner = 0
  414.           put netError(gNetID) & "No Connection"
  415.           gCheckPing = 0
  416.           doExit = 1
  417.         else
  418.           gpTicks = gpTicks + 1
  419.           put netError(gNetID) & "Waiting"
  420.         end if
  421.       end if
  422.     else
  423.       put "Nothing"
  424.       gNewBanner = 0
  425.       gCheckPing = 0
  426.       doExit = 1
  427.     end if
  428.   else
  429.     doExit = 1
  430.   end if
  431.   return doExit
  432. end
  433.  
  434. on bdWebCommunicate urlString, newBrowser
  435.   if newBrowser = VOID then
  436.     newBrowser = 0
  437.   end if
  438.   put "WebComm:" && urlString && newBrowser
  439.   isSw = the runMode contains "Plugin"
  440.   if isSw = 1 then
  441.     if newBrowser = 1 then
  442.       gotoNetPage(urlString, "_new")
  443.     else
  444.       gotoNetPage(urlString)
  445.     end if
  446.   else
  447.     gsOpenURL(urlString)
  448.   end if
  449. end
  450.  
  451. on bdGetNetText urlString
  452.   put "getNetText:" && urlString
  453.   return getNetText(urlString)
  454. end
  455.